package models

import (
	r "ansible-api-go/cache"
	"fmt"

	"github.com/garyburd/redigo/redis"
)

//var c:= r.Pool.Get()
/*
type RConn struct {
	Conn *redis.Pool
}

RConn = {}
RConn = r.Pool
*/
func Setdata() (err error) {
	c := r.Pool.Get()
	_, err = c.Do("set", "test", "444")
	if err != nil {
		return err
	}
	return nil
}

func Lpushdata(key string, value string) (err error) {
	c := r.Pool.Get()
	_, err = c.Do("rpush", key, value)
	if err != nil {
		fmt.Println("rpush data error")
		//return errors.New("lpush data error")
		return err
	}
	return nil
}

func Lpopdata(key string) (data string, err error) {
	c := r.Pool.Get()
	data, err = redis.String(c.Do("lpop", key))
	if err != nil {
		fmt.Println(err)
	}
	return data, err
}

/*

func (k RConn) Setdata2() (err error) {
	c := k.RConn.Conn.Get
	_, err = c.Do("set", "test1", "666")
	if err != nil {
		return err
	}
	return nil
}


type Tasks struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

func (t *Tasks) AddTask() (err error) {

	c := r.Pool.Get()
	_, err = c.Do("set", t.Key, t.Value)
	if err != nil {
		fmt.Println(err)
		return
	}
	return err
}

func Setdata(key, value string) (err error) {
	c := r.Pool.Get()
	_, err = c.Do("set", key, vlaue)
	if err != nil {
		fmt.Println(err)
		return
	}
	return err
}

/*
func Getdata(key string) (data string, err error) {
	c := r.Pool.Get()
	data, err = c.Do("get", key)
	if err != nil {
		fmt.Println(err)
		return err
	}
	fmt.Println(data)
	return data, nil
}
*/
/*

	conn.Do("set", "test", "222")

func Ping(c redis.Conn) error {
	// Send PING command to Redis

	pong, err := c.Do("PING")
	if err != nil {
		return err
	}

	// PING command returns a Redis "Simple String"
	// Use redis.String to convert the interface type to string
	s, err := redis.String(pong, err)
	if err != nil {
		return err
	}

	fmt.Printf("PING Response = %s\n", s)
	// Output: PONG

	return nil
}

func SET(c redis.Conn) error {
	_, err := c.Do("SET", "Favorite Movie", "Repo Man")
	if err != nil {
		return err
	}
	_, err = c.Do("SET", "Release Year", 1984)
	if err != nil {
		return err
	}
	return nil
}
*/
